﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;

namespace mdk.Cenas
{
    class OptionsMenu
    {
         KeyboardState teclado, teclado_anterior;

        Texture2D menu;

        Rectangle obj;

        enum Options { HELP, SOUND_SETUP, JOYSTICK, KEYBOARD, PERFORMANCE, SKILL, DISPLAY, QUIT, Count };
        Options current_option;

        String[] menuLabels = new String[] { "Help", "Sound Setup", "Joystick", "Keyboard", "Performance", "Skill - ", "Display", "Quit" };
       
        SoundEffect change_option, select_option;
    
        SpriteFont menuFont, menuFontSelected;

        

        public OptionsMenu(ContentManager content)
        {
            menu = content.Load<Texture2D>("img/black");           

            obj = new Rectangle(0, 0, 700, 525);            

            current_option = Options.HELP;
           
            select_option = content.Load<SoundEffect>("audio/BEEP1C");
            change_option = content.Load<SoundEffect>("audio/BEEP2C");          

            menuFont = content.Load<SpriteFont>("font/MenuFont");
            menuFontSelected = content.Load<SpriteFont>("font/MenuFontSelected");          
            

        }

        public void Update(GameTime gameTime, GraphicsDeviceManager g)
        {           

            teclado = Keyboard.GetState();         

            //alterna opções
            if (teclado.IsKeyDown(Keys.Up) && (teclado_anterior != teclado))
            {
                current_option--;
                change_option.Play();
            }
            else if (teclado.IsKeyDown(Keys.Down) && (teclado_anterior != teclado))
            {
                current_option++;
                change_option.Play();
            }
            

            //realiza o loop entre as opções
            if (current_option == Options.Count)
                current_option = 0;
            if (current_option < 0)
                current_option = Options.Count - 1;
            

            if (teclado.IsKeyDown(Keys.Enter) && (teclado_anterior != teclado))
            {
                select_option.Play();

                switch (current_option)
                {
                    case Options.HELP:
                        
                        break;
                    case Options.KEYBOARD:
                        Gerenciador.cena_atual = Gerenciador.Cena.KEYBOARD;
                        break;
                    case Options.SKILL:

                        Gerenciador.current_skill++;

                        if (Gerenciador.current_skill == Gerenciador.Skill.Count)
                            Gerenciador.current_skill = 0;

                        break;
                   
                    case Options.QUIT:
                        Gerenciador.cena_atual = Gerenciador.Cena.MENU;
                        break;

                }
                
            }

            teclado_anterior = teclado;


        }

        public void Draw(GameTime gameTime, SpriteBatch tela)
        {

            tela.Draw(menu, obj, Color.White);


            Vector2 position = new Vector2(obj.Width / 2, 30);
            SpriteFont font;
            String label;
         
            for (int i = 0; i < (int)Options.Count; i++)
            {  

                font = (i == (int)current_option ? menuFontSelected : menuFont);

                label = menuLabels[i];
                if (menuLabels[i] == "Skill - ")
                    label += Gerenciador.current_skill.ToString();

                position.X -= font.MeasureString(label).X / 2;
                
                if (((Options) i == Options.QUIT) || ((Options) i == Options.SKILL))            //opçoes que ainda n funcionam
                    tela.DrawString(font, label, position, Color.Goldenrod);
                else
                    tela.DrawString(font, label, position, Color.Silver);

                position.Y += 60;
                position.X = obj.Width / 2;
                
            }            

        }      

    
    }
}
